function waitI2C( port )
  while( 0 ~= nxt.I2CGetStatus( port ) ) do
  end
end

function setupI2C(port)
  nxt.InputSetType(port,2)
  nxt.InputSetDir(port,1,1)
  nxt.InputSetState(port,1,1)

  nxt.I2CInitPins(port)
end

function GetColourCode(port) -- Maps to a set of NXT colour codes, small range (16?) not to accurate 
	nxt.I2CSendData(port, string.char( 0x02, 0x42 ), 8)
	waitI2C(port)
	return string.byte(nxt.I2CRecvData(port))
end

function GetRGB(port) -- Gives a 0-255 code for each RGB value.
	nxt.I2CSendData(port, string.char( 0x02, 0x43 ), 8)
	waitI2C(port)
	red = string.byte(nxt.I2CRecvData(port))
	nxt.I2CSendData(port, string.char( 0x02, 0x44 ), 8)
	waitI2C(port)
	green = string.byte(nxt.I2CRecvData(port))
	nxt.I2CSendData(port, string.char( 0x02, 0x45 ), 8)
	waitI2C(port)
	blue = string.byte(nxt.I2CRecvData(port))
	return red, green, blue
end